/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package pl.put.dcs_modeler.visualModelEditor.actions;

import java.util.HashMap;
import java.util.logging.Logger;
import org.openide.DialogDisplayer;
import org.openide.NotifyDescriptor;
import org.openide.filesystems.FileObject;
import org.openide.filesystems.FileUtil;
import org.openide.nodes.Node;
import org.openide.util.HelpCtx;
import org.openide.util.NbBundle;
import org.openide.util.actions.CookieAction;
import pl.put.dcs_modeler.fileTypeDataLoader.DCSComputingModelDataObject;
import pl.put.dcs_modeler.visualModelEditor.windowComponenets.CFMWindowTopComponent;

public final class OpenDCSComputingModel extends CookieAction
{

    private static Logger log =
            Logger.getLogger( OpenDCSComputingModel.class.getName() );

    protected void performAction( Node[] activatedNodes )
    {
        DCSComputingModelDataObject dCSComputingModelDataObject = ( activatedNodes[0].getLookup().lookup( DCSComputingModelDataObject.class ) );

        FileObject f = dCSComputingModelDataObject.getPrimaryFile();
        String displayName = FileUtil.getFileDisplayName( f );
        String msg = "I am " + displayName + ". Hear me roar!";
        log.info( "!!!!!!!!!!!!! " + msg + "!!!!!!!!!!!!!!!!!!!" );
        log.info( dCSComputingModelDataObject.getFileContent() );
        
        /*if ( CFMWindowTopComponent.isInstaceExist() )
        {
            msg = "Okno projektu jest otwarte. Jezeli chcesz zaczac prace z innym, musisz wykonac akcje zapisu, bo stracisz bezpowrtonie dane";
            NotifyDescriptor nd = new NotifyDescriptor.Message( msg );
            DialogDisplayer.getDefault().notify( nd );
        } 
        else
        {*/
        CFMWindowTopComponent win = CFMWindowTopComponent.findInstance( dCSComputingModelDataObject );//new CFMWindowTopComponent( dCSComputingModelDataObject );
        win.open();
        win.requestActive();
            //win.createComputingObject( "Cos tam", 200, 200, in, out );
       // }
    }

    protected int mode()
    {
        return CookieAction.MODE_EXACTLY_ONE;
    }

    public String getName()
    {
        return NbBundle.getMessage( OpenDCSComputingModel.class, "CTL_OpenDCSComputingModel" );
    }

    protected Class[] cookieClasses()
    {
        return new Class[]
                {
                    DCSComputingModelDataObject.class
                };
    }

    @Override
    protected String iconResource()
    {
        return "pl/put/resources/project_icon_16_16.png";
    }

    public HelpCtx getHelpCtx()
    {
        return HelpCtx.DEFAULT_HELP;
    }

    @Override
    protected boolean asynchronous()
    {
        return false;
    }
}

